version 13.0
log using "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\figure3.log", replace
#delimit ;

*     ***************************************************************** *;
*     ***************************************************************** *;
*       File-Name:      figure3.do                                      *;
*       Date:           January 14, 2019                                *;
*       Author:         MRG/CC                                          *;
*       Purpose:      	Produce Figure 3 for It's Not Only What You     *;
*                       Say, It's Also How You Say It: The Strategic    *;
*                       Use Of Campaign Sentiment. Journal of Politics. *;
*                       Forthcoming.                                    *;
* 	    Input File:     sentiment.dta                                   *;
*       Output File:    figure3.log                                     *;
*       Data Output:    none                                            *;             
*       Previous file:  sentiment.dta                                   *;
*       Machine:        desktop/laptop                     				*;
*     ****************************************************************  *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*        Load data                                                      *;
*     ****************************************************************  *;

use "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\sentiment.dta", clear;

*     ****************************************************************  *;
*       Declare data to be panel, where the panel is based on language  *;
*     ****************************************************************  *;

xtset language;

xtsum positive_sentiment;

*     ****************************************************************  *;
*       Generate additional variables that we will need for our         *;
*       analysis.                                                       *;
*     ****************************************************************  *;

gen incumbent_inflation_l = incumbent*inflation_l;
label var incumbent_inflation "incumbent*inflation_l";
gen incumbent_unemployment_l = incumbent*unemployment_l;
label var incumbent_unemployment_l "incumbent*unemployment_l";
gen incumbent_pm = incumbent*pm;
label var incumbent_pm "incumbent*pm";
gen incumbent_fm = incumbent*fm;
label var incumbent_fm "incumbent*fm";
gen left_right2=left_right*left_right;
label var left_right2 "left_right*left_right";
gen extremist = 0;
replace extremist=1 if family_id ==14 | family_id==40;
replace extremist = . if family_id==.;
label var extremist "1 if communist/socialist or far right, 0 otherwise";
gen extremist2 = 0;
replace extremist2=1 if family_id ==14 | family_id==40 | family_id==19;
replace extremist2 = . if family_id==.;
label var extremist2 "1 if communist/socialist, far right, or greens, 0 otherwise";
gen extremist_inflation_l=extremist*inflation_l;
label var extremist_inflation "extremist*inflation_l";
gen extremist_unemployment_l=extremist*unemployment_l;
label var extremist_unemployment_l "extremist*unemployment_l";

tabulate language, gen(l);

*     ****************************************************************  *;
*      Change graph scheme	                                            *;
*     ****************************************************************  *;

ssc install scheme-burd, replace;

*     ****************************************************************  *;
*     ****************************************************************  *;
*       Produce Figure 3                                                *;
*     ****************************************************************  *;
*     ****************************************************************  *;

matrix crab = J(3,2,.);
matrix coln crab = estimate se;
*reg positive_sentiment incumbent incumbent_pm l1 l3 l4 l5 l6 l7, cluster(election_id);
bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm, fe;
lincom _cons*1;
matrix crab[1,1] = r(estimate);
matrix crab[1,2] = r(se);
lincom _cons*1 + incumbent*1;
matrix crab[2,1] = r(estimate);
matrix crab[2,2] = r(se);
lincom _cons*1 + incumbent*1 + incumbent_pm*1;
matrix crab[3,1] = r(estimate);
matrix crab[3,2] = r(se);
coefplot (matrix(crab[.,1]), se(crab[.,2]) offset(0) 
        lwidth(thick) m(smcircle) mfcolor("126 163 204") mlc("126 163 204") 
        ciop(lcolor("126 163 204"))), legend(off) 
        xtitle("") ytitle("Positive Sentiment", size(3)) levels(95)   
        coeflabels(r1="Opposition Party" r2="Non-PM Incumbent Party" r3="PM Incumbent Party",  tlcolor(black) labcolor(black) labsize(2.5)) 
        grid(n) yscale(noline) xscale(noline)
        ylab(1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6, tlcolor(black) labcolor(black) labsize(2.5))  
        yline(0, lcolor(gray)) vertical scheme(burd);

graph export "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\fig3.pdf", replace;

*     ****************************************************************  *;
*       Replication complete                                            *;
*     ****************************************************************  *;

log close;

clear;



